export default function Dep() {
    this.watchers = []
}

Dep.target = null
const targetStack = []

Dep.prototype.depend = function () {
    if (this.watchers.includes(Dep.target)) return
    this.watchers.push(Dep.target)
}

Dep.prototype.notify = function () {
    for (let watcher of this.watchers) watcher.update()
}

export function targetPush(watcher) {
    targetStack.push(watcher)
    Dep.target = watcher
}

export function targetPop() {
    targetStack.pop()
    Dep.target = targetStack[targetStack.length - 1]
}